package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @author hyh
 * @version 1.0
 */
@Mapper
public interface OrdersMapper {
    /**
     * 添加到订单表中
     * @param orders
     */
    void insert(Orders orders);
    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 订单分页查询
     * @param ordersPageQueryDTO
     * @return
     */
    Page<Orders> pageSelect(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据订单id查询订单
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders getById(@Param("id") Integer id);

    @Select("select delivery_time from orders where number = #{orderNumber}")
    String selectDeliveryTime(@Param("orderNumber") String orderNumber);

    void updateNUM(Orders orders);

    /**
     * 查询待派送数量
     * @return
     */
    @Select("select count(*) from orders where status = 3")
    Integer selectConfirmed();

    /**
     *派送中数量
     * @return
     */
    @Select("select count(*) from orders where status = 4")
    Integer selectDeliveryInProgress();

    /**
     *待接单数量
     * @return
     */
    @Select("select count(*) from orders where status = 2")
    Integer selectToBeConfirmed();

    /**
     * 查询超时的订单
     * @param pendingPayment
     * @param time
     * @return
     */
    @Select("select * from orders where status = #{pendingPayment} and order_time < #{time}")
    List<Orders> selectOutTime(Integer pendingPayment, LocalDateTime time);

    /**
     * 查询营业额
     * @param map
     * @return
     */
    Double selectRangeOfDay(Map map);
}
